import request from '@/utils/request'
import type {
  CategoryInfo,
  CategoryQueryParams,
  CategoryListResponse,
  CategoryDetailResponse,
  CategoryOperationResponse,
  CategoryFormData
} from './types'

// 获取品类列表
export function getCategoryList(params: CategoryQueryParams): Promise<CategoryListResponse> {
  return request({
    url: '/protocol/category/list',
    method: 'get',
    params
  })
}

// 获取品类详情
export function getCategoryDetail(categoryId: string | number): Promise<CategoryDetailResponse> {
  return request({
    url: `/protocol/category/${categoryId}`,
    method: 'get'
  })
}

// 新增品类
export function addCategory(data: CategoryFormData): Promise<CategoryOperationResponse> {
  return request({
    url: '/protocol/category',
    method: 'post',
    data
  })
}

// 修改品类
export function updateCategory(data: CategoryFormData): Promise<CategoryOperationResponse> {
  return request({
    url: '/protocol/category',
    method: 'put',
    data
  })
}

// 删除品类
export function deleteCategory(categoryIds: number[]): Promise<CategoryOperationResponse> {
  return request({
    url: `/protocol/category/${categoryIds.join(',')}`,
    method: 'delete',
    // data: {
    //   categoryIds
    // }
  })
}

// 修改品类状态
export function changeCategoryStatus(categoryId: string | number, status: string): Promise<CategoryOperationResponse> {
  return request({
    url: '/device/list/changeStatus',
    method: 'put',
    data: {
      categoryId,
      status
    }
  })
}

// 导出品类
export function exportCategory(params: CategoryQueryParams): Promise<any> {
  return request({
    url: '/protocol/category/export',
    method: 'post',
    data: params,
    responseType: 'blob'
  })
}